<template>
  <mt-button size="small" plain :disabled="disabled" @click="getCaptcha">{{ checkInfo }}</mt-button>
</template>

<script>
  export default {
    name: 'zh-sms-button',
    data() {
      return {
        disabled: false,
        checkInfo: ''
      }
    },
    props: {
      text: {
        type: String,
        default: '发送验证码'
      }
    },
    mounted() {
      this.checkInfo = this.text
    },
    methods: {
      delay() {
        // 按钮延迟
        let delay = 60
        this.checkInfo = '等待(' + delay + 's)'
        this.disabled = true
        let timer = setInterval(() => {
          this.checkInfo = '等待(' + --delay + 's)'
          if(delay < 0) {
            clearTimeout(timer)
            this.checkInfo = '发送验证码'
            this.disabled = false
          }
        }, 1000)
      },
      getCaptcha() {
        this.$emit('click')
      }
    }
  }
</script>

<style>
</style>
